﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3.Admin
{
    public partial class login : System.Web.UI.Page
    {
        private DataClassesHeaxlthDataContext dc = new DataClassesHeaxlthDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ImageButtonLogin_Click(object sender, ImageClickEventArgs e)
        {
            string username = this.userlogin.Value.ToString();
            string password = this.passlogin.Value.ToString();
            AdminLogin ad;
            
            if (adminlogin(username, password)!= null )
            {
                string abc = mahoa_giaima.giaiMa(adminlogin(username, password).password);
                if ((abc == password))
                {
                    Response.Redirect("home.aspx");
                }
                else
                {
                    Labelkiemtra.Text = "Account Not found";
                }

            }
            else
            {
                
                Labelkiemtra.Text = "Account Not found";
            }


        }
        public AdminLogin adminlogin(string username, string password)
        {
            AdminLogin ad = new AdminLogin();
            try
            {

                ad = dc.AdminLogins.Where(am => am.username.Equals(username) ).ToList().First();
                Session["admin"] = ad;
            }
            catch
            {
                ad = null;
            }
            return ad;
        }

    }
}